/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.scene.controller;

import com.koron.common.Excel;
import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.domain.DataBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.scene.bean.CalibrationView;
import com.koron.scene.domain.DeviceCalibration;
import com.koron.scene.domain.DeviceCalibrationRelation;
import com.koron.scene.service.api.DeviceCalibrationService;
import com.koron.scene.utils.BusinessCode;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.swan.bean.MessageBean;
import springfox.documentation.annotations.ApiIgnore;

import java.io.File;
import java.io.InputStream;
import java.util.*;

@Api(tags = "deviceCalibration", description = "设备检验接口")
@RestController
@RequestMapping("/deviceCalibration")
public class DeviceCalibrationController {

    private final static  Logger logger = LoggerFactory.getLogger(DeviceCalibrationController.class);

    @Autowired
    private DeviceCalibrationService deviceCalibrationService;

    private void setProperties(DeviceCalibration source, StaffBean user) {
        source.setAddTime(new Date());
        source.setAddUser(user.getCode());
        source.setAddUserName(user.getName());
        source.setUpdateUserName(user.getName());
        source.setUpdateTime(source.getAddTime());
        source.setUpdateUser(user.getCode());
    }


    @ApiOperation("存储设备检验记录")
    @RequestMapping(value = "/save.htm", method = {RequestMethod.POST})
    @Log(title = "新增、修改设备检验记录", businessModule = "设备检验", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<String> save(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestBody DeviceCalibration deviceCalibration) {
        if (user == null) {
            return MessageBean.create(BusinessCode.NO_LOGIN.getCode(), BusinessCode.NO_LOGIN.getDescription(), String.class);
        }
        if (deviceCalibration == null) {
            return MessageBean.create(BusinessCode.SUCCESS.getCode(), BusinessCode.SUCCESS.getDescription(), String.class);
        }
        if (StringUtils.isBlank(deviceCalibration.getTitle()) || StringUtils.isBlank(deviceCalibration.getResponsibleEmployeeCode()) || StringUtils.isBlank(deviceCalibration.getResponsibleEmployeeName())) {
            return MessageBean.create(BusinessCode.INSUFFICIENT_PARAM.getCode(), BusinessCode.INSUFFICIENT_PARAM.getDescription(), String.class);
        }
        setProperties(deviceCalibration, user);
        MessageBean<String> msg = deviceCalibrationService.persist(deviceCalibration);
        if (msg.getCode() == BusinessCode.SUCCESS.getCode()) {
            msg.setData(msg.getData());
        }
        return msg;
    }


    @ApiOperation("批量删除设备检验记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids", value = "检验记录Id,多个之间用逗号分开", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/batchDelete.htm", method = RequestMethod.POST)
    @Log(title = "批量删除设备检验记录", businessModule = "设备检验", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean<Boolean> batchDelete(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String ids) {
        if (user == null) {
            return MessageBean.create(BusinessCode.NO_LOGIN.getCode(), BusinessCode.NO_LOGIN.getDescription(), Boolean.class);
        }
        MessageBean<Boolean> msg = new MessageBean<>();
        if (StringUtils.isEmpty(ids)) {
            return MessageBean.create(BusinessCode.SUCCESS.getCode(), BusinessCode.SUCCESS.getDescription(), Boolean.class);
        }
        try {
            String[] idArray = ids.split("[,，]");
            for (String id : idArray) {
                DeviceCalibration deviceCalibration = deviceCalibrationService.fetchOne(id);
                if (deviceCalibration.getStatus() != 0) {
                    return MessageBean.create(BusinessCode.CHECK_CANNOT_REMOVE.getCode(), BusinessCode.CHECK_CANNOT_REMOVE.getDescription(), Boolean.class);
                }
            }
            msg.setData(deviceCalibrationService.batchDetele(Arrays.asList(idArray)));
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
            msg.setCode(BusinessCode.SUCCESS.getCode());
            return msg;
        } catch (Exception e) {
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }


    @ApiOperation("查询设备检验记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "title", value = "标题" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "responsibleEmployeeName", value = "设备负责人姓名" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "calibrationCorp", value = "检验单位" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0草稿、1审核中、2审核通过" , dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "keyword", value = "关键词" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/list.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<DeviceCalibration>> list(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = false) String corpCode, @RequestParam(required = false) String title, @RequestParam(required = false) String responsibleEmployeeName,
                                                         @RequestParam(required = false) String calibrationCorp, @RequestParam(required = false) Integer status,@RequestParam(required = false) String keyword,
                                                         @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "15") Integer pageSize) {
        if (null == user) {
            MessageBean<DataBean<DeviceCalibration>> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<DataBean<DeviceCalibration>> msg = new MessageBean<>();
        Integer start = (page <= 1) ? 0 : (page - 1) * pageSize;
        try {
            DataBean<DeviceCalibration> dataBean = deviceCalibrationService.fetchCalibrations(corpCode, title, responsibleEmployeeName, calibrationCorp, status, start, pageSize,keyword);
            msg.setData(dataBean);
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
        } catch (Exception e) {
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
        }
        return msg;
    }


    @ApiOperation("设备检验记录详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/detail.htm", method = RequestMethod.POST)
    public MessageBean<DeviceCalibration> detail(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = true) final String id) {
        if (null == user) {
            MessageBean<DeviceCalibration> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<DeviceCalibration> msg = new MessageBean<>();
        if (StringUtils.isEmpty(id)) {
            msg.setCode(BusinessCode.INSUFFICIENT_PARAM.getCode());
            msg.setDescription(BusinessCode.INSUFFICIENT_PARAM.getDescription());
            return msg;
        }
        try {
            msg.setData(deviceCalibrationService.fetchOne(id));
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
            return msg;
        } catch (Exception e) {
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
            return msg;
        }
    }


    @ApiOperation("存储设备检验结果明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deviceId", value = "设备Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "description", value = "检查内容描述" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "normal", value = "检验结果是否正常" , dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "result", value = "检验结果描述" , dataType = "boolean", paramType = "query"),
            @ApiImplicitParam(name = "calibrationDate", value = "检验日期" , dataType = "date", paramType = "query"),
            @ApiImplicitParam(name = "validationDate", value = "有效日期" , dataType = "date", paramType = "query")
    })
    @RequestMapping(value = "/saveResult.htm", method = RequestMethod.POST)
    @Log(title = "新增、修改设备检验结果明细", businessModule = "设备检验", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<Boolean> saveResult(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestBody DeviceCalibrationRelation relation) {
        if (null == user) {
            MessageBean<Boolean> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<Boolean> msg;
        Integer result = deviceCalibrationService.saveCalibrationRelation(relation);
        BusinessCode bc = BusinessCode.valueOf(result);
        msg = MessageBean.create(bc.getCode(), bc.getDescription(), Boolean.class);
        return msg;
    }


    @ApiOperation("查询设备检查明细列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "responsibleEmployeeCode", value = "设备检验责任人code", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数" , dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/queryCalibrationResult.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<CalibrationView>> queryCalibrationResult(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String corpCode, @RequestParam String responsibleEmployeeCode, @RequestParam String deviceCalibrationId,
                                                                         @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize) {
        if (null == user) {
            MessageBean<DataBean<CalibrationView>> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<DataBean<CalibrationView>> msg = new MessageBean<>();
        Integer start = null;
        if (null != page && null != pageSize) {
            start = (page <= 1) ? 0 : (page - 1) * pageSize;
        }
        msg.setData(deviceCalibrationService.fetchDeviceInCalibration(corpCode, responsibleEmployeeCode, deviceCalibrationId, start, pageSize));
        msg.setCode(BusinessCode.SUCCESS.getCode());
        msg.setDescription(BusinessCode.SUCCESS.getDescription());
        return msg;
    }

    @ApiOperation("查询设备检查单条明细详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "responsibleEmployeeCode", value = "设备检验责任人code", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, dataType = "String", paramType = "query"),
    })
    @RequestMapping(value = "/queryOneCalibrationResult.htm", method = RequestMethod.POST)
    public MessageBean<CalibrationView> queryOneCalibrationResult(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String corpCode,
                                                                  @RequestParam String responsibleEmployeeCode, @RequestParam String deviceCalibrationId, @RequestParam String deviceId) {
        MessageBean<CalibrationView> msg = new MessageBean<>();
        if (null == user) {
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        CalibrationView calibrationView = deviceCalibrationService.fetchOneDeviceInCalibration(corpCode, responsibleEmployeeCode, deviceCalibrationId, deviceId);
        msg.setData(calibrationView);
        msg.setCode(BusinessCode.SUCCESS.getCode());
        msg.setDescription(BusinessCode.SUCCESS.getDescription());
        return msg;
    }

    @ApiOperation("查询检验记录下所有设备信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "responsibleEmployeeCode", value = "设备检验责任人code", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "deviceIds", value = "列表已存在的设备Id集合", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "page", value = "当前页" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "每页条数" , dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/queryAllCalibrationResult.htm", method = RequestMethod.POST)
    public MessageBean<DataBean<CalibrationView>> queryAllCalibrationResult(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String corpCode, @RequestParam String responsibleEmployeeCode, @RequestParam String deviceCalibrationId, @RequestParam String deviceIds,
                                                                            @RequestParam(required = false) Integer page, @RequestParam(required = false) Integer pageSize) {
        if (null == user) {
            MessageBean<DataBean<CalibrationView>> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<DataBean<CalibrationView>> msg = new MessageBean<>();
        Integer start = null;
        if (null != page && null != pageSize) {
            start = (page <= 1) ? 0 : (page - 1) * pageSize;
        }
        responsibleEmployeeCode = responsibleEmployeeCode.split("_")[0];
        msg.setData(deviceCalibrationService.fetchAllDeviceInCalibration(corpCode, responsibleEmployeeCode, deviceCalibrationId, deviceIds, start, pageSize));
        msg.setCode(BusinessCode.SUCCESS.getCode());
        msg.setDescription(BusinessCode.SUCCESS.getDescription());
        return msg;
    }


    @ApiOperation("新增设备检查明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deviceIds", value = "设备id集合字符串", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/addCalibrationRelation.htm", method = RequestMethod.POST)
    public MessageBean<Integer> addCalibrationRelation(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String corpCode, @RequestParam String deviceCalibrationId, @RequestParam String deviceIds) {
        if (null == user) {
            MessageBean<Integer> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        return deviceCalibrationService.addCalibrationRelation(corpCode, deviceCalibrationId, deviceIds);
    }


    @ApiOperation("删除设备检查明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deviceId", value = "设备id", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/deleteCalibrationRelation.htm", method = RequestMethod.POST)
    public MessageBean<Integer> deleteCalibrationRelation(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String corpCode, @RequestParam String deviceCalibrationId, @RequestParam String deviceId) {
        if (null == user) {
            MessageBean<Integer> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        return deviceCalibrationService.deleteCalibrationRelation(corpCode, deviceCalibrationId, deviceId);
    }

    @ApiOperation("上传设备检验的附件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "delFileAddress", value = "要删除的照片的地址，多个之间用；分开" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "keepFileAddress", value = "要保留的照片的地址,多个之间用；分开" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "files", value = "附件" , dataType = "MultipartFile", paramType = "query")
    })
    @RequestMapping(value = "/uploadAttachment.htm", method = RequestMethod.POST)
    public MessageBean<Boolean> uploadAttachment(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String deviceCalibrationId, @RequestParam(required = false) String delFileAddress,
                                                 @RequestParam(required = false) String keepFileAddress, @RequestParam(required = false) MultipartFile[] files) {
        if (null == user) {
            MessageBean<Boolean> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<Boolean> msg = new MessageBean<>();
        Boolean flag = deviceCalibrationService.uploadCalibrationAttachment(deviceCalibrationId, delFileAddress, keepFileAddress, files);
        msg.setData(flag);
        if (flag) {
            msg.setCode(BusinessCode.SUCCESS.getCode());
            msg.setDescription(BusinessCode.SUCCESS.getDescription());
        } else {
            msg.setCode(BusinessCode.EXCEPTION.getCode());
            msg.setDescription(BusinessCode.EXCEPTION.getDescription());
        }
        return msg;
    }


    @ApiOperation("查询设备检验的附件")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/queryAttachment.htm", method = RequestMethod.POST)
    public MessageBean<List<String>> getAttachment(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String deviceCalibrationId) {
        if (null == user) {
            MessageBean<List<String>> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<List<String>> msg = new MessageBean<>();
        msg.setData(deviceCalibrationService.getCalibrationAttachment(deviceCalibrationId));
        msg.setCode(BusinessCode.SUCCESS.getCode());
        msg.setDescription(BusinessCode.SUCCESS.getDescription());
        return msg;
    }


    @ApiOperation("设备检验结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCalibrationId", value = "设备检验记录Id", required = true, dataType = "String", paramType = "query")
    })
    @RequestMapping(value = "/submit.htm", method = RequestMethod.POST)
    public MessageBean<Boolean> submit(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam String deviceCalibrationId) {
        if (null == user) {
            MessageBean<Boolean> messageBean = new MessageBean<>();
            messageBean.setCode(BusinessCode.NO_LOGIN.getCode());
            messageBean.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return messageBean;
        }
        MessageBean<Boolean> msg = new MessageBean<>();
        if (user == null) {
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        if (StringUtils.isEmpty(deviceCalibrationId)) {
            msg.setCode(BusinessCode.INSUFFICIENT_PARAM.getCode());
            msg.setDescription(BusinessCode.INSUFFICIENT_PARAM.getDescription());
            return msg;
        }
        DeviceCalibration deviceCalibration = deviceCalibrationService.fetchOne(deviceCalibrationId);
        if (deviceCalibration == null) {
            msg.setCode(BusinessCode.NO_CHECK_RECORD.getCode());
            msg.setDescription(BusinessCode.NO_CHECK_RECORD.getDescription());
            return msg;
        }
        return deviceCalibrationService.submit(user, deviceCalibration);
    }


    @ApiOperation("设备检验记录列表导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code" , paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "title", value = "标题" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "responsibleEmployeeName", value = "设备负责人姓名" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "calibrationCorp", value = "检验单位" , dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "status", value = "状态：0草稿、1审核中、2审核通过" , dataType = "int", paramType = "query"),
    })
    @RequestMapping(value = "/exportList.htm", method = RequestMethod.GET)
    public HttpEntity<?> exportList(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @RequestParam(required = false) String corpCode, @RequestParam(required = false) String title, @RequestParam(required = false) String responsibleEmployeeName,
                                    @RequestParam(required = false) String calibrationCorp, @RequestParam(required = false) Integer status) {
        if (null == user) {
            return null;
        }
        Map<String, Object> map = new HashMap<>();
        File file = new File("static/excel/deviceCalibrationList.xlsx");
        try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("static/excel/deviceCalibrationList.xlsx")) {
            List<DeviceCalibration> list = deviceCalibrationService.exportList(corpCode, title, responsibleEmployeeName, calibrationCorp, status);
            map.put("data", list);
            FileUtils.copyInputStreamToFile(inputStream, file);
        } catch (Exception e) {
            logger.error(e.getMessage(),e);
            logger.error(e.getMessage(),e);
        }
        return Excel.createFile("设备检验记录台账", file, "deviceCalibrationList.btl", map);
    }


}
